package com.seednia.module.core.post.dto;

import java.util.Date;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang.StringUtils;

import com.seednia.foundation.framework.dto.AbstractRecord;
import com.seednia.foundation.framework.dto.ICriteria;
import com.seednia.foundation.framework.util.RecordUtils;
import com.seednia.module.core.search.util.AbstractQueryBuilder;

/**
 * Post Criteria Class to query records
 *
 * @author Young Suk Ahn
 */
@XmlRootElement(name = "PostCriteria", 
		namespace = "http://seednia.com/core/1.0")
@XmlType(name = "PostCriteria")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PostCriteria extends PostDto implements ICriteria {
	
	public static final int RETRIEVE_SCOPE_SINGLE_AUTHOR = 1;
	public static final int RETRIEVE_SCOPE_PROJECT = 2;
	public static final int RETRIEVE_SCOPE_ALL = 3;

	/**
	 * 
	 */
	private static final long serialVersionUID = 4906746614002362662L;
	
	private int _retrieveScope;
	
	private List<Long> userSids = null; // list of user sids (this criteria is OR-ed)
	private List<Long> projectSids = null; // list of projects (this criteria is OR-ed)

	public PostCriteria(){
		RecordUtils.initCriteria(this);
	}
	
	@Override
	public Date getCreatedBefore() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Date getCreatedAfter() {
		// TODO Auto-generated method stub
		return null;
	}

	public int get_retrieveScope() {
		return _retrieveScope;
	}

	public void set_retrieveScope(int _retrieveScope) {
		this._retrieveScope = _retrieveScope;
	}
	
	
	public List<Long> getUserSids() {
		return userSids;
	}

	public void setUserSids(List<Long> userSids) {
		this.userSids = userSids;
	}

	public List<Long> getProjectSids() {
		return projectSids;
	}

	public void setProjectSids(List<Long> projectSids) {
		this.projectSids = projectSids;
	}

	@Override
	public void setSearchText(String value)
	{
		super.setBody(value);
		super.setSubject(value);
	}
	
	
	
	/**
	 * To create object from JSONP string
	 * Used by the REST framework when sending this object as parameter
	 * @param jsonStr
	 * @return
	 */
	public static PostCriteria fromString(String jsonStr) {
		PostCriteria retval = null;
		try {
			retval = (PostCriteria) AbstractRecord.fromString(PostCriteria.class, jsonStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retval;
	}

}
